package cn.xz.tipsum.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.WindowManager
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.SimpleItemAnimator
import cn.xz.tipsum.R
import cn.xz.tipsum.adapter.ErrorListAdapter
import cn.xz.tipsum.bean.*
import cn.xz.tipsum.databinding.ActivityErrorBinding

class ErrorActivity : AppCompatActivity() {

    private lateinit var mDataBind: ActivityErrorBinding

    private val mAdapter by lazy { ErrorListAdapter() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
        mDataBind = DataBindingUtil.setContentView(this, R.layout.activity_error)
        initRv()
        initData()
        initEvent()
    }

    private fun initRv(){
        mDataBind.rvList.apply {
            layoutManager = LinearLayoutManager(this@ErrorActivity)
            adapter = mAdapter
            //RecyclerView闪烁问题
            (itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
        }
        mAdapter.setList(mErrorList)
        mAdapter.setOnItemClickListener { adapter, view, position ->
            jump(position)
        }
    }

    private fun initData(){
    }

    private fun initEvent(){
        mDataBind.apply {
            tvBack.setOnClickListener {
                finish()
            }
        }

    }

    private fun jump(t: Int){
        val intent = Intent(this@ErrorActivity, IndexActivity::class.java)
        intent.putExtra(JUMP_TYPE,t)
        startActivity(intent)
    }

}